<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <title>一起农场吧</title>
    <meta name="viewport" content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="full-screen" content="true" />
    <meta name="screen-orientation" content="portrait" />
    <meta name="x5-fullscreen" content="true" />
    <meta name="360-fullscreen" content="true" />
    <style>
        html, body {
            -ms-touch-action: none;
            background: #333333;
            padding: 0;
            border: 0;
            margin: 0;
            height: 100%;
        }
         #preloading{
            position: fixed;
            margin: auto;
            width: 100%;
            height: 0;
            padding-top: 177.73%;
            background-image: url(https://game-farm.oss-cn-hangzhou.aliyuncs.com/2001/resource/assets/loading/loading1.jpg);
            background-size:100%;
            background-repeat: no-repeat;
            background-position: top center;
        }
        #preloading #box{
            position: absolute;
            width: 82.4%;
            height: 0;
            padding-top: 15.07%;
            top: 35.18%;
            left: 8.8%;
        }
        #box .text{
            position: absolute;
            color: #fff;
            text-align: center;
            height:50%;
            width: 100%;
            top: 26%;
            font-size:0.18rem;
            line-height: 100%;
        }
        #box #progress{
            position: absolute;
            top: 0;
            overflow: hidden;
        }
        #box #progress img{
            position: absolute;
            height: 100%;
        }

        .alertImg{
            display: none;
            position: fixed;
            width: 100%;
            height: 100%;
            z-index: 999;
        }
        .alertImg .close{
            position: absolute;
            width:12%;
            height: 7%;
            background: url(https://game-farm.oss-cn-hangzhou.aliyuncs.com/2001/resource/assets/icon_close.png);
            background-size: 100%;
            background-repeat: no-repeat;
            background-position: center center;
            right: 1%;
            top: 1%;
        }
        .alertImg img{
            width: 100%;
            height: 100%;
            z-index: 9999;
        }
        #request{
            position: fixed;
            overflow: scroll;
            width: 80%;
            top: 10%;
            left: 10%;
            height: 80%;
            margin: auto;
            background-color: #fff;
            display: none;
        }
        p{
            line-height: 20px;
            margin:0;
        }
        #button{
            position: fixed;
            width: 50px;
            height: 50px;
            border-radius: 50px;
            bottom: 40px;
            left: 8px;
            background-color: rgb(123, 114, 233);
            color: rgb(255, 255, 255);
            line-height: 50px;
            text-align: center;
        }
    </style>
</head>
<body>
    <div id="preloading">
        <div id="box">
			<div id="progress">
				<img src="http://17pkmj.image.alimmdn.com/2001/resource/assets/loading/Progressbar_2.png">
			</div>
			<div class="text">正在创建您的农场，请稍后...</div>
		</div>
    </div>
    <div id="egretPlayerBox" style="position: fixed;width: 100%;height: 100%">
        <div id="egretPlayer" style="margin: auto;width: 100%;height: 100%;" class="egret-player"
            data-entry-class="Main"
            data-orientation="portrait"
            data-scale-mode="fixedWidth"
            data-frame-rate="30"
            data-content-width="750"
            data-content-height="1206"
            data-multi-fingered="2"
            data-show-fps="false" data-show-log="false"
            data-show-fps-style="x:0,y:0,size:12,textColor:0x333333,bgAlpha:0.9">
        </div>
    </div>
    <div id="alertImg" class="alertImg">
        <div id="close" class="close"></div>
        <img id="img" src="">
    </div>
    <!--<audio id="bgMusic" src="http://17pkmj.image.alimmdn.com/2001/resource/assets/music1.mp3" autoplay='autoplay' loop="loop">你的浏览器不支持audio标签。</audio>   -->
<script type="text/javascript"src="./jweixin-1.3.0.js"></script>
<script>
    var isWxMini = false;
    wx.ready(function() { 
        isWxMini = window.__wxjs_environment === 'miniprogram';
    })
    function getWxMini(){
        return isWxMini;
    }
    function toPayWx(data){
        //把要用到的参数传到小程序中进行支付
        var path = '/pages/pay/pay?timeStamp='+data.timeStamp+'&nonceStr='+data.nonceStr+'&package='+data.package+'&signType='+data.signType+'&paySign='+data.sign;
        wx.miniProgram.navigateTo({
            url: path
        })
    }
</script>
<script>
    (function (doc, win) {  
        var width = document.body.clientWidth / 375 * 100;
        var current = 100;
        if(width !== 100){
            current = width;
        }
        document.getElementsByTagName('html')[0].style.fontSize = current + 'px';
    })(document, window); 

    var total = 0;
    var current = 0;

    var box = document.getElementById("box");
	var progress = document.getElementById("progress");

	var box_w = box.offsetWidth;
	var box_h = box.offsetHeight;

	progress.style.width = 0;
	progress.style.height = box_h + "px";

    function onProgress(){
        progress.style.width = (current/total) * box_w + "px";
    }
</script>
<script>
    document.addEventListener('touchmove',bodyScroll, false);
    document.getElementById('preloading').addEventListener('touchstart', function (event) {
        event.stopPropagation();
        event.preventDefault();
    },false);
    document.getElementById('preloading').addEventListener('touchmove',function(event){
        event.preventDefault();
        event.stopPropagation();
    },false);
    document.getElementById('egretPlayerBox').addEventListener('touchstart', function (event) {
        event.stopPropagation();
        event.preventDefault();
    },false);

    function bodyScroll(event){
        event.preventDefault();
    }
</script>
<script>
    var alertImg = document.getElementById("alertImg");
    function alertImgShow(){
        alertImg.style.display = "block";
    }
    function hideImgShow(){
        alertImg.style.display = "none";
    }
    function setImgSrc(src){
        var img = document.getElementById("img");
        img.src = src;
    }
    document.getElementById('close').addEventListener('click',function(){
        hideImgShow();
    })
</script>
<script>
    var browser={
        versions:function(){
            var u = navigator.userAgent, app = navigator.appVersion;
            return {//移动终端浏览器版本信息
            trident: u.indexOf('Trident') > -1, //IE内核
            presto: u.indexOf('Presto') > -1, //opera内核
            webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
            gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
            mobile: !!u.match(/AppleWebKit.*Mobile.*/)||u.indexOf('iPad') > -1, //是否为移动终端
            ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
            android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
            iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
            iPad: u.indexOf('iPad') > -1, //是否iPad
            webApp: u.indexOf('Safari') == -1 //是否web应该程序，没有头部与底部
            };
        }(),
        language:(navigator.browserLanguage || navigator.language).toLowerCase()
    }
    if(browser.versions.iPad || !browser.versions.mobile){
        document.getElementById("egretPlayer").setAttribute("data-scale-mode","showAll");
    }

    if(browser.versions.mobile){
        var width = document.body.clientWidth;
        var height = document.body.clientHeight;
        if(width / height > 0.66){
            document.getElementById("egretPlayer").setAttribute("data-scale-mode","showAll");
        }
    }
    
    var loadScript = function (list, callback) {
        var loaded = 0;
        var loadNext = function () {
            loadSingleScript(list[loaded], function () {
                loaded++;
                if (loaded >= list.length) {
                    callback();
                }
                else {
                    loadNext();
                }
            })
        };
        loadNext();
    };
    var loadSingleScript = function (src, callback) {
        var s = document.createElement('script');
        s.async = false;
        s.src = src;
        s.addEventListener('load', function () {
            current = current + 1;
            onProgress();
            s.parentNode.removeChild(s);
            s.removeEventListener('load', arguments.callee, false);
            callback();
        }, false);
        document.body.appendChild(s);
    };
    var xhr = new XMLHttpRequest();
    var url = "";
    if(location.href.indexOf("h5-pre.farm.pk0818.com") !== -1){
        url = "https://game-farm.oss-cn-hangzhou.aliyuncs.com/2001/resource/manifest.json";
    }else{
        url = "./manifest.json";
    }
    xhr.open('GET', url + '?v=' + Math.random(), true);
    // xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
    xhr.addEventListener("load", function () {
        var manifest = JSON.parse(xhr.response);
        var list = manifest.initial.concat(manifest.game);
        total = list.length;
        loadScript(list, function () {
            /**
             * {
             * "renderMode":, //Engine rendering mode, "canvas" or "webgl"
             * "audioType": 0 //Use the audio type, 0: default, 2: web audio, 3: audio
             * "antialias": //Whether the anti-aliasing is enabled in WebGL mode, true: on, false: off, defaults to false
             * "calculateCanvasScaleFactor": //a function return canvas scale factor
             * }
             **/
            egret.runEgret({ renderMode: "webgl", audioType: 0, calculateCanvasScaleFactor:function(context) {
                var backingStore = context.backingStorePixelRatio ||
                    context.webkitBackingStorePixelRatio ||
                    context.mozBackingStorePixelRatio ||
                    context.msBackingStorePixelRatio ||
                    context.oBackingStorePixelRatio ||
                    context.backingStorePixelRatio || 1;
                return (window.devicePixelRatio || 1) / backingStore;
            }});
            setTimeout(function(){
                document.getElementById("preloading").style.display = "none";   
            },1000);
        });
    });
    xhr.send(null);
    
    // function setBgm(play){  
    //     var bgm = document.getElementById('bgmMusic');  
    //     if(play){  
    //         bgm.play();  
    //     }else{  
    //         bgm.pause();  
    //     }  
    // }  
    // setBgm(true); 
    //window["setBgm"](true)
    // document.addEventListener('DOMContentLoaded', function () {
    //     function audioAutoPlay() {
    //         var audio = document.getElementById('bgmMusic');
    //             audio.play();
    //         document.addEventListener("WeixinJSBridgeReady", function () {
    //             audio.play();
    //         }, false);
    //     }
    //     audioAutoPlay();
    // });
</script>
</body>

</html>